package com.project.fortuneteller.exception;

import cn.hutool.core.util.ObjectUtil;

import java.util.function.Supplier;

public enum UserBusinessErrorEnum implements IError {

    USER_CODE_LIMIT_DAY("001", "当日单据编号已达上限，请明日再试"),
    USER_FIND_BY_ID("002", "根据id找不到数据,请联系客服处理"),
    USER_NOT_LOGIN("407", "您未登录，请重新登录"),
    USER_EDIT_NOT_SUPPORT("105", "当前单据状态不允许编辑，请检查"),
    USER_SUBMIT_NOT_SUPPORT("106", "当前单据状态不允许提交，请检查"),
    USER_AUDIT_NOT_SUPPORT("107", "当前单据状态不允许审核，请检查"),
    USER_DELETE_NOT_SUPPORT("108", "当前单据状态不允许删除，请检查"),
    USER_TYPE_DELETE_NOT_SUPPORT("109", "当前单据类型暂未开放删除，请检查"),
    USER_NOT_FOUND("110", "单据不存在，请检查"),
    USER_PROCESS_NOT_FOUND("112", "暂未配置有效的流程，请联系管理员解决。跟踪信息：区划-{}，单位-{}，表单-{}"),
    USER_LOGIN_TIMEOUT("401", "登录已过时，请重新登录"),
    ;

    public final static String ERROR_CODE_PREFIX = "USER-ERROR";
    public final static String CONNECTION_SYMBOL = "_";

    private final String code;

    private final String message;

    private String statusCode;


    UserBusinessErrorEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    UserBusinessErrorEnum(String code, String message, String statusCode) {
        this.code = code;
        this.message = message;
        this.statusCode = statusCode;
    }


    public static Supplier<UserBusinessException> supply(UserBusinessErrorEnum errorEnum) {
        return () -> new UserBusinessException(errorEnum);
    }

    @Override
    public String getMessage() {
        return message;
    }


    @Override
    public String getErrorCode() {
        return ERROR_CODE_PREFIX.concat(CONNECTION_SYMBOL).concat(this.code);
    }

    /**
     * 获取状态。
     * @return
     */
    @Override
    public String getStatusCode() {
        return  ObjectUtil.defaultIfNull(this.statusCode, StatusCodeEnum.BAD_REQUEST.getCode());
    }
}
